package cn.lingyangwl.agile.system.controller;

import cn.lingyangwl.agile.infra.module.group.model.rqrs.DataGroupDeleteReq;
import cn.lingyangwl.agile.infra.module.group.model.rqrs.DataGroupSaveReq;
import cn.lingyangwl.agile.infra.module.group.model.rqrs.DataGroupUpdateReq;
import cn.lingyangwl.agile.model.enums.DataGroupBizTypeEnum;
import cn.lingyangwl.agile.ram.ActionType;
import cn.lingyangwl.agile.ram.RamResource;
import cn.lingyangwl.agile.system.model.rqrs.menu.*;
import cn.lingyangwl.agile.system.service.MobileMenuService;
import cn.lingyangwl.framework.core.response.Resp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

/**
 * 移动端菜单
 * 
 * @author shenguangyang
 */
@Api(tags = "移动端菜单")
@RestController
@RequestMapping("/mobileMenu")
public class MobileMenuController {
    @Resource
    private MobileMenuService mobileMenuService;

    @ApiOperation(value = "查询移动端菜单")
    @GetMapping("/list")
    @RamResource(action = "sys:mobileMenu:query", name = "查询移动端菜单", type = ActionType.READ)
    public Resp<List<MobileMenuResp>> listMobileMenu(@Validated MobileMenuListReq req) {
        return Resp.ok(mobileMenuService.listMobileMenu(req));
    }

    @ApiOperation(value = "通过id查找移动端菜单")
    @GetMapping("/get")
    @RamResource(action = "sys:mobileMenu:query", name = "查询移动端菜单", type = ActionType.READ)
    public Resp<MobileMenuResp> getMobileMenu(@RequestParam(value = "id") Long id) {
        return Resp.ok(mobileMenuService.getMobileMenu(id));
    }
  
    @ApiOperation(value = "保存移动端菜单")
    @PostMapping("/save")
    @RamResource(action = "sys:mobileMenu:save", name = "保存移动端菜单", type = ActionType.WRITE)
    public Resp<?> saveMobileMenu(@Validated @RequestBody MobileMenuSaveReq req) {
        return Resp.ok(mobileMenuService.saveMobileMenu(req));
    }
  
    @ApiOperation(value = "更新移动端菜单")
    @PostMapping("/update")
    @RamResource(action = "sys:mobileMenu:update", name = "更新移动端菜单", type = ActionType.WRITE)
    public Resp<?> updateMobileMenu(@Validated @RequestBody MobileMenuUpdateReq req) {
        return Resp.ok(mobileMenuService.updateMobileMenu(req));
    }
  
    @ApiOperation(value = "批量删除移动端菜单")
    @DeleteMapping("/batchDelete")
    @RamResource(action = "sys:mobileMenu:delete", name = "删除移动端菜单", type = ActionType.WRITE)
    public Resp<?> batchDeleteMobileMenu(@RequestParam(value = "ids") List<Long> ids) {
        return Resp.ok(mobileMenuService.batchDeleteMobileMenu(ids));
    }
  
    @ApiOperation(value = "删除移动端菜单")
    @DeleteMapping("/delete")
    @RamResource(action = "sys:mobileMenu:delete", name = "删除移动端菜单", type = ActionType.WRITE)
    public Resp<?> deleteMobileMenu(@RequestParam(value = "id") Long id) {
        return Resp.ok(mobileMenuService.deleteMobileMenu(id));
    }

    @ApiOperation(value = "删除移动端菜单组")
    @DeleteMapping("/deleteGroup")
    @RamResource(action = "sys:mobileMenu:deleteGroup", name = "删除移动端菜单组", type = ActionType.WRITE)
    public Resp<?> deleteGroup(@RequestParam(value = "id") Long id) {
        DataGroupDeleteReq req = new DataGroupDeleteReq();
        req.setBizType(DataGroupBizTypeEnum.MOBILE_MENU.getType());
        req.setIds(Collections.singletonList(id));
        return Resp.ok(mobileMenuService.deleteGroup(req));
    }

    @ApiOperation(value = "批量删除移动端菜单组")
    @DeleteMapping("/batchDeleteGroup")
    @RamResource(action = "sys:mobileMenu:deleteGroup", name = "删除字典组", type = ActionType.WRITE)
    public Resp<?> batchDeleteGroup(@RequestParam(value = "ids") List<Long> ids) {
        DataGroupDeleteReq req = new DataGroupDeleteReq();
        req.setBizType(DataGroupBizTypeEnum.MOBILE_MENU.getType());
        req.setIds(ids);
        return Resp.ok(mobileMenuService.deleteGroup(req));
    }

    @ApiOperation(value = "保存移动端菜单组")
    @PostMapping("/saveGroup")
    @RamResource(action = "sys:mobileMenu:saveGroup", name = "保存移动端菜单组", type = ActionType.WRITE)
    public Resp<Long> saveDataGroup(@RequestBody DataGroupSaveReq req) {
        req.setBizType(DataGroupBizTypeEnum.MOBILE_MENU.getType());
        return Resp.ok(mobileMenuService.saveGroup(req));
    }

    @ApiOperation(value = "更新移动端菜单组")
    @PostMapping("/updateGroup")
    @RamResource(action = "sys:mobileMenu:updateGroup", name = "更新移动端菜单组", type = ActionType.WRITE)
    public Resp<?> updateDataGroup(@RequestBody DataGroupUpdateReq req) {
        return Resp.ok(mobileMenuService.updateGroup(req));
    }

}
